<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>渠道政策 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>

    <script src="<%=path %>/resource/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <form id="chn_pol_form">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <div class="btnsBox inLC">
                    <span id="addPolBtn" class="sq-button sq-button-round l-dialog-btn-ok">添加</span>
                    <span id="delPolBtn" class="sq-button sq-button-round co_normal l-dialog-btn-cancel">删除</span>
                </div>
                <span>渠道政策</span>
            </div>
            <div class="sqPanel_body">
                <div id="ligergrid_pol" class="sq-grid"></div>
            </div>
        </div>
        <div class="btnsBox">
	        <span id="savePolBtn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
	    </div>
    </form>
</div>

<script type="text/javascript">
    var polGrid = null;
    $(function () {
        var insCompId = "${insCompId}";
        var chnCd = "${chnCd}";

        var prdTypList = [];
        var insTypList = [];
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/insurance/insCompChnPol/getInsDictList.do',
            success: function (msg) {
                if (msg.success == 1) {
                    prdTypList = msg.data.prdTypCdList;
                    insTypList = msg.data.insTypCdList;

                    /**渠道政策**/
                    polGrid = $("#ligergrid_pol").ligerGrid({
                        url: '<%=path%>/insurance/insCompChnPol/initList.do?insCompId=' + insCompId,
                        method: 'get',
                        columns: [
                            {
                                display: '保险产品类型', name: 'prdTypCd', minWidth: 100, align: 'left',
                                editor: {
                                    type: 'select',
                                    data: prdTypList,
                                    valueField: 'key',
                                    textField: 'value'
                                },
                                render: function (item) {
                                    for (var j = 0; j < prdTypList.length; j++) {
                                        if (prdTypList[j]['key'] == item.prdTypCd) {
                                            return prdTypList[j]['value'];
                                        }
                                    }
                                    return item.prdTypCdNm;
                                }
                            },
                            {
                                display: '保险种类', name: 'insTypCd', minWidth: 100, align: 'left',
                                editor: {
                                    type: 'select',
                                    data: insTypList,
                                    valueField: 'key',
                                    textField: 'value'
                                },
                                render: function (item) {
                                    for (var i = 0; i < insTypList.length; i++) {
                                        if (insTypList[i]['key'] == item.insTypCd)
                                            return insTypList[i]['value']
                                    }
                                    return item.insTypCdNm;
                                }
                            },
                            {
                                display: '返利比例(格式0.12)', name: 'rebPct', minWidth: 100, align: 'center',
                                editor: {type: 'number',precision: 2,toFix: true,
                                    onToFix: function () {
                                        $.ligerDialog.SQalert({
                                            SQ_type: "warning",
                                            content: "小数点后面最多2位！"
                                        });
                                    }
                                },
                            },
                            /*{
                                display: '折扣系数', name: 'disRat', minWidth: 100, align: 'center', type: 'int',
                                editor: {type: 'int', precision: 0}, validate: {number: true, maxlength: 1}
                            },*/
                            {
                                display: '首次折扣系数', name: 'fstDisRat', minWidth: 100, align: 'center',editor: {type: 'text'},
                            },
                            {
                                display: '续保折扣系数', name: 'renewDisRat', minWidth: 100, align: 'center', editor: {type: 'text'}
                            },
                        ],
                        onSelectRow: function (rowdata, rowindex) {
                        },
                        onBeforeEdit: function (e) {

                        },
                        onBeforeSubmitEdit: function (e) {
                            if (e.column.columnname == "prdTypCd") {
                                e.record.prdTypCd = e.value;
                            }
                            if (e.column.columnname == "insTypCd") {
                                e.record.insTypCd = e.value;
                            }
                        },
                        usePager: false,
                        pageSize:100,
                        root: 'rows',
                        record: 'total',
                        hideLoadButton: true,
                        width: '100%',
                        height: '100%',
                        heightDiff: -2,
                        enabledEdit: true,
                        isScroll: true,
                        checkbox: true,
                        rownumbers: true,
                        allowUnSelectRow: true,
                        alternatingRow: true
                    });

                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

        $("#chn_pol_form").ligerForm({
            validate: true
        });

        /* 新增 */
        $("#addPolBtn").click(function (event) {
            polGrid.addRow({
                prdTypCd: '',
                insTypCd: '',
                rebPct: 0,
                disRat: 0
            });
        });

        /* 删除 */
        $("#delPolBtn").click(function (event) {
            polGrid.deleteSelectedRow();
        });


        /* 保存修改 */
        $("#savePolBtn").click(function (event) {
            $(document).trigger('click');
            var data = polGrid.getData();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {data: JSON.stringify(data)},
                url: '<%=path%>/insurance/insCompChnPol/addCompChnPol.do?insCompId=' + insCompId + '&chnCd=' + chnCd,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        polGrid.reload();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

    });


</script>

</body>
</html>
